package cn.wx.service;


import java.util.List;
import java.util.Objects;

import cn.wx.entity.UserInfo;
import cn.wx.repository.UserInfoRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * @author stevezhao
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoRepository userInfoRepository;

    @Override
    public Page<UserInfo> queryUserPage(Integer current, Integer size) {
        if (current != null && size != null) {
            // 设置分页
            PageRequest page = PageRequest.of(current, size);
            Page<UserInfo> infoPage = userInfoRepository.findAll(page);
            return infoPage;
        }
        return null;
    }

    @Override
    public void saveOrUpdate(UserInfo userInfo) {
        if (Objects.nonNull(userInfo)) {
            userInfoRepository.save(userInfo);
        }
    }

    @Override
    public void deleteUserById(Long id) {
        if (Objects.nonNull(id)) {
            userInfoRepository.deleteById(id);
        }
    }

    @Override
    public List<UserInfo> listUserInfo() {
        return userInfoRepository.findAll();
    }
}
